$(function () {
    var mydate = new Date();
    var s=getFormatDate(mydate);
    var myChart = echarts.init(document.getElementById('main'));
    // 基于准备好的dom，初始化echarts实例
    // 指定图表的配置项和数据
    var option = {
        title: {
            text: '日订单量走势'
        },
        color:['green'],
        tooltip: {},
        legend: {
            data:['销量']
        },
        xAxis: {
            data: [dateOperate(s,0,0,-5).substring(5),
                dateOperate(s,0,0,-4).substring(5),
                dateOperate(s,0,0,-3).substring(5),
                dateOperate(s,0,0,-2).substring(5),
                dateOperate(s,0,0,-1).substring(5),
                dateOperate(s,0,0,0).substring(5)]
        },
        yAxis: {},
        series: [{
            name: '销量',
            type: 'bar',
            data: [5, 20, 36, 10, 10, 20]
        }]
    };
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);

    var myChart2 = echarts.init(document.getElementById('main2'));
    // 基于准备好的dom，初始化echarts实例
    // 指定图表的配置项和数据
    var option2 = {
        title: {
            text: '月订单量走势'
        },
        tooltip: {},
        legend: {
            data:['销量']
        },
        xAxis: {
            data: [dateOperate(s,0,-5,0).substring(0,7),
                dateOperate(s,0,-4,0).substring(0,7),
                dateOperate(s,0,-3,0).substring(0,7),
                dateOperate(s,0,-2,0).substring(0,7),
                dateOperate(s,0,-1,0).substring(0,7),
                dateOperate(s,0,0,0).substring(0,7)]
        },
        yAxis: {},
        series: [{
            name: '销量',
            type: 'bar',
            data: [5, 20, 36, 10, 10, 20]
        }]
    };
    // 使用刚指定的配置项和数据显示图表。
    myChart2.setOption(option2);
    function dateOperate(strDate, year, month, day) {
        // 格式化日期转日期对象
        var dateTime = eval('new Date(' + strDate.replace(/\d+(?=-[^-]+$)/, function (a) {
            return parseInt(a, 10) - 1;
        }).match(/\d+/g) + ')');
        // 日期对象加year年（year为负数表示减year年）
        dateTime = new Date(dateTime.setFullYear(dateTime.getFullYear() + year));
        // 日期对象加month月（month为负数表示减month月）
        dateTime = new Date(dateTime.setMonth(dateTime.getMonth() + month));
        // 日期对象加day日（day为负数表示减day日）
        dateTime = new Date(dateTime.setDate(dateTime.getDate() + day));
        return getFormatDate(dateTime);
    }
    function getFormatDate(date) {
        var year = date.getFullYear();
        var month = (date.getMonth() + 1).toString();
        var day = (date.getDate()).toString();
        if (month.length == 1) {
            month = "0" + month;
        }
        if (day.length == 1) {
            day = "0" + day;
        }
        var dateTime = year + "-" + month + "-" + day;
        return dateTime;
    }

});